﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WanPiJie.Utilities;

namespace WanPiJie.WebSite.Management
{
	public partial class Attribute : PageBase
	{
		protected ProductCatalog ProductCatalog
		{
			get;
			set;
		}

		public IList<ProductAttribute> AttributeList
		{
			get;
			set;
		}

		protected override void HttpGetProcess()
		{
			String catalogId = this.QV("cg");
			if (String.IsNullOrEmpty(catalogId))
				ShowMessage("参数错误", "Default.aspx");
			else
			{
				this.Initialize(Int32.Parse(catalogId));
			}
		}

		protected override void HttpPostProcess()
		{
			String attributeName = PV("attributeName");
			if (String.IsNullOrEmpty(attributeName))
				ShowMessage(String.Format("请输入要给{0}添加的属性名称", this.ProductCatalog.Name));
			else
			{
				Int32 catalogId = Int32.Parse(PV("cag"));
				ProductService.Instance.AddAttributeToCatalog(catalogId, attributeName);
				this.Initialize(catalogId);
			}
		}

		private void Initialize(Int32 catalogId)
		{
			this.ProductCatalog = ProductService.Instance.GetCatalogById(catalogId);
			this.AttributeList = ProductService.Instance.GetAttributeByCatalog(catalogId);
		}
	}
}